package cn.zhf.shop.service.impl;

import cn.hutool.json.JSONUtil;
import cn.zhf.shop.entity.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.zhf.shop.mapper.OrganizationTypeMapper;
import cn.zhf.shop.entity.organization.OrganizationType;
import cn.zhf.shop.service.OrganizationTypeService;

import java.util.List;

@Service
public class OrganizationTypeServiceImpl implements OrganizationTypeService{

    @Resource
    private OrganizationTypeMapper organizationTypeMapper;
    private Logger logger= LoggerFactory.getLogger(getClass());


    @Override
    public Message deleteByPrimaryKey(Integer id) {
        logger.info("删除组织类别：{}",id);
        return organizationTypeMapper.deleteByPrimaryKey(id)>0?Message.success("删除成功"+id):Message.fail("删除失败"+id);
    }

    @Override
    public Message insert(OrganizationType record) {
        logger.info("删除组织类别：{}", JSONUtil.toJsonStr(record));
        return organizationTypeMapper.insert(record)>0 ? Message.success("添加成功"):Message.fail("失败成功");
    }

    @Override
    public Message<OrganizationType> selectByPrimaryKey(Integer id) {
        logger.info("获得组织类别详情：{}", id);
        OrganizationType orgType=organizationTypeMapper.selectByPrimaryKey(id);
        return orgType==null?Message.fail("无记录"):Message.success(null).add(orgType);
    }


    @Override
    public Message updateByPrimaryKey(OrganizationType record) {
        logger.info("更新组织类别：{}", JSONUtil.toJsonStr(record));
        return organizationTypeMapper.updateByPrimaryKey(record)>0 ? Message.success(null):Message.fail(null);
    }

    @Override
    public Message<List<OrganizationType>> selectAll() {
        List<OrganizationType> organizationTypeList=organizationTypeMapper.selectAll();
        return organizationTypeList==null?Message.fail(null):Message.success(null).add(organizationTypeList);
    }

    @Override
    public String selectTypeNameById(Integer id) {
        return organizationTypeMapper.selectTypeNameById(id);
    }

}
